const { AVLTree } = require('./AVL_tree');

// 创建AVL树实例
const avlTree = new AVLTree();

console.log('=== AVL树使用示例 ===');

// 插入数据
console.log('\n1. 插入数据:');
const words = [
    {key: 5, value: 'hello'},
    {key: 3, value: 'world'},
    {key: 7, value: 'apple'},
    {key: 2, value: 'banana'},
    {key: 4, value: 'cherry'},
    {key: 6, value: 'date'},
    {key: 8, value: 'elderberry'}
];

words.forEach(word => {
    avlTree.insert(word.key, word.value);
    console.log(`插入键${word.key}: ${word.value}`);
});

console.log('\n2. 前序遍历（显示树结构）:');
console.log(avlTree.preOrder());

console.log('\n3. 中序遍历（按键排序）:');
console.log(avlTree.inOrder());

console.log('\n4. 查找操作:');
console.log('查找键4:', avlTree.search(4));
console.log('查找键10:', avlTree.search(10));

console.log('\n5. 树信息:');
console.log('树高度:', avlTree.getTreeHeight());
console.log('树是否为空:', avlTree.isEmpty());

console.log('\n6. 删除操作:');
avlTree.delete(3);
console.log('删除键3后的前序遍历:');
console.log(avlTree.preOrder());

console.log('\n=== 示例结束 ===');